#include <iostream>

#include "code/binaryFileParser.hpp"
#include "runtime/interpreter.hpp"
#include "runtime/global.hpp"

using namespace std;

int main(int argc, char** argv) {
    const char* fileName;
    if(argc <= 1){
        // printf("pyvm_2025 need .pyc fileName\n");
        // return 0;
        // fileName = "D:/c/vmware_share/pyvm_2025/py3/__pycache__/test_while_all.cpython-38.pyc";
        // fileName = "D:/c/vmware_share/pyvm_2025/py3/pyc3.8.10/test_while2.cpython-38.pyc";
        fileName = "D:/c/vmware_share/pyvm_2025/py3/__pycache__/test_fun_upper.cpython-38.pyc";
    }else{
        fileName = argv[1];
    }

    Global::init();

    cout << "parse begin fileName = " << fileName << endl;
    BufferedInputStream input(fileName);
    BinaryFileParser parser(&input);
    CodeObject* code = parser.parse();
    cout << "parse end" << endl << endl;

    cout << "run begin" << endl;
    Interpreter interpreter;
    interpreter.run(code);
    cout << "run end" << endl;

    return 0;
}
